<?php
/**
 *
 * @package avp
 * @version $Id: $
 * @copyright (c) 2006 Jan-Willem van Ganswijk, Stefan van Essen
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
define( 'IN_SCRIPT', 'TRUE' ); //Voor de evil haxx0rz.

$root = '../';

include( $root . 'includes/common.inc.php' );
include( $root . 'includes/lang.inc.php' );
include( $root . 'includes/session.class.php' );
include( $root . 'includes/template.class.php' );
include( $root . 'includes/admin.inc.php' );

$session = new sessionWrapper();
$lang = read_langfiles( 'admin_common,admin_about' );
$template = new template( $CONFIG['theme'] );
$template->add_var( 'active', 'about' );

if( !$session->check_login() ) {
    die( print_error( $lang['ERROR_NEEDLOGIN'], 'login.php', true ) );
}
$result = $db->query( "SELECT * FROM `" . $db->get_table( 'avatar' ) . "`" );
$template->add_var( 'avatarcount', $db->get_num_rows( $result ) );
$db->free_result( $result );

$result = $db->query( "SELECT * FROM `" . $db->get_table( 'images' ) . "`" );
$template->add_var( 'imagecount', $db->get_num_rows( $result ) );

$imagesize = 0;
while( $row = $db->fetch( $result ) ) {
    $fileinfo = stat( $root . "images/image-" . $row["imageid"] . "." . $row["ext"] );
    $imagesize += $fileinfo['size'];
}
$template->add_var( 'imagesize', decodeSize( $imagesize ) );
$template->add_var( 'free_disk_space', decodeSize( disk_free_space( realpath( $root . 'images/' ) ) ) );

$db->free_result( $result );

include( $root . 'templates/' . $CONFIG['theme'] . '/theme.cfg.php');
$template->add_var( 'themedetails',$theme);
$template->add_var( 'langdetails', get_langdetails( $CONFIG["lang"] ) );
$template->add_var( 'authors', $AUTHORS );

$template->append('libs', array('name' => 'Smarty', 'version' => $template->get_smarty_version(),'url' => 'http://www.smarty.net'));

$template->set_title( $lang['TITLE_ABOUT'] );

$template->add_templates( 'admin_header,admin_about,admin_footer' );
$template->make_page();

function decodeSize( $bytes )
{
    $types = array( 'B', 'KiB', 'MiB', 'GiB', 'TiB' );
    for( $i = 0; $bytes >= 1024 && $i < ( count( $types ) -1 ); $bytes /= 1024, $i++ );
    return( round( $bytes, 2 ) . " " . $types[$i] );
}

?>